package com.example.safeassistan.home.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.safeassistan.R;
import com.example.safeassistan.base.BaseVPFragment;
import com.example.safeassistan.common.UserData;
import com.example.safeassistan.risk.model.RiskPointDetailModel;
import com.example.safeassistan.widget.ViewPagerForScrollView;

public class RiskDetailBasicInfoFragment extends BaseVPFragment {
    private Context context;
    private View view;
    private RiskPointDetailModel model;
    private ViewPagerForScrollView pager;
    private TextView tvRiskPointTitle,tvQymc,tvDepartName,tvLevel,tvAddress,
            tvOwer,tvStatus;
    private LinearLayout llAddress;


    public RiskDetailBasicInfoFragment(ViewPagerForScrollView pager , RiskPointDetailModel model) {
        this.pager = pager;
        this.model=model;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_riskdetail_basicinfo, container, false);
            pager.setObjectForPosition(view,0);
            context = getActivity();
            initView();
        }
        return view;
    }

    public void initView(){
        tvRiskPointTitle=view.findViewById(R.id.tvRiskPointTitle);
        tvQymc=view.findViewById(R.id.tvQymc);
        llAddress=view.findViewById(R.id.llAddress);
        tvDepartName=view.findViewById(R.id.tvDepartName);
        tvLevel=view.findViewById(R.id.tvLevel);
        tvAddress=view.findViewById(R.id.tvAddress);
        tvOwer=view.findViewById(R.id.tvOwer);
        tvStatus=view.findViewById(R.id.tvStatus);

        tvDepartName.setText(model.getResult().getDepartName());
        tvQymc.setText(model.getResult().getQymc()==null?"":model.getResult().getQymc());
        tvRiskPointTitle.setText(model.getResult().getRiskPointName());

        if (model.getResult().getRiskLevel()!=null){
            switch (model.getResult().getRiskLevel()){
                case 1:
                    tvLevel.setText("重大");
                    break;
                case 2:
                    tvLevel.setText("较大");
                    break;
                case 3:
                    tvLevel.setText("一般");
                    break;
                case 4:
                    tvLevel.setText("较低");
                    break;
            }
        }

//        if (UserData.create(context).get(UserData.ls_jc).equals("1")){
//            llAddress.setVisibility(View.GONE);
//            tvAddress.setText(model.getResult().getRiskPointPlaces());
//        }else {
//            llAddress.setVisibility(View.GONE);
//        }

        //责任人
        tvOwer.setText(model.getResult().getRealname()==null?"":model.getResult().getRealname());
        switch (model.getResult().getIsOutOfControl()){
            case 0:
                tvStatus.setText("可控");
                break;
            case 1:
                tvStatus.setText("预警");
                break;
        }
    }

    @Override
    protected void onFragmentVisibleChange(boolean isVisible) { }

    @Override
    protected void onFragmentFirstVisible() { }
}